package main;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class LabExecutor implements Executor {
	private int scientists;
	private int working;
	private ExecutorService pool;
	public LabExecutor(int scientists) {
		working=0;
		this.scientists = scientists;
		pool = Executors.newCachedThreadPool();
	}

	@Override
	public void execute(Runnable command) {
		if (working<scientists)
		{
			pool.execute(command);
			working++;
		}
	}
	
	public int getWorking()
	{
		return working;
	}
	
	public void addScientist()
	{
		scientists++;
	}
	public void freeScientist()
	{
		working--;
	}

	public void shutdown() {
		pool.shutdown();
		
	}
}
